package cardCollections;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.swing.JOptionPane;

import Distributive.casinoRoyale;
import cards.Card;

/**
 * 
 * @author akazero1
 * 
 */

public class Shoe {
	private List<Card> deck;
	private casinoRoyale theCasino;

	public Shoe() throws IOException {
		deck = new ArrayList<Card>();
		// theCasino = new casinoRoyale();
	}

	/**
	 * Requires: card != null
	 * 
	 * @param card
	 *            Ensures: this.deck.size() = this.deck.size@pre + 1
	 */
	public void addCard(Card card) {
		deck.add(card);
	}

	/**
	 * Requires: Nothing Ensures: Nothing
	 * 
	 * Returns the size of the deck.
	 * 
	 * @return = this.deck.size()
	 */
	public int getSizeOfDeck() {
		return deck.size();
	}

	/**
	 * Requires: Nothing Ensures: Nothing
	 * 
	 * Returns number of cards remaining in the deck.
	 * 
	 * @return deck.size() - index
	 */
	public int getNumberOfCardsRemaining() {
		return deck.size();
	}

	/**
	 * Requires: Nothing Ensures: deck.size > index, index = index@pre + 1,
	 * currCard != null
	 * 
	 * @return currCard
	 * @throws IOException
	 */
	public Card dealCard() throws IOException {
		if (0 == deck.size())
			this.restoreDeck();
		Card currCard = deck.get(0);
		// theCasino.sendCard(currCard);
		deck.remove(0);
		// index++;
		return currCard;
	}

	/**
	 * Requires: Nothing Ensures: deck@pre[1] != deck[1]
	 */
	public void shuffle() {
		Collections.shuffle(deck);
	}

	/**
	 * Requires: Nothing Ensures: Nothing
	 * 
	 * Returns true if deck is empty and false if deck is not.
	 * 
	 * @return
	 */
	public boolean isEmpty() {
		if (0 == deck.size())
			return true;
		else
			return false;
	}

	/**
	 * Requires: Nothing Ensures: deck.size() == 52*6;
	 * 
	 * Restores deck to a complete deck.
	 * 
	 * @throws IOException
	 */
	public void restoreDeck() throws IOException {
		deck.clear();
		FixedDeck f;
		for (int i = 0; i < 6; i++) {
			f = new FixedDeck();
			deck.addAll(f.getFixedDeck());
		}
		shuffle();
	}

	/**
	 * Requires: deck != null Ensures: Nothing
	 * 
	 * @return s = string representation of Card c.
	 */
	public String toString() {
		String s = "";
		for (Card c : deck) {
			s += c.toString() + "\n";
		}
		return s;
	}

}
